<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="选择店铺：" prop="sellerLoginId">
        <el-select v-model="queryParams.sellerLoginId" placeholder="请选择店铺" filterable class="width3">
          <el-option v-for="(item,index) in storeList" :key="index" :label="item.storeName"
                     :value="item.storeUserName"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单编号：" prop="orderId">
        <el-input v-model="queryParams.orderId" placeholder="请输入订单编号" clearable
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-button type="primary" size="mini" @click="isShowAeOrder = true">从速卖通获取全部订单</el-button>
      <el-button type="success" size="mini" @click="isShowAeOneOrder = true">从速卖通获取单个订单</el-button>
      <el-button type="primary" size="mini" @click="isOpenOfflineLogisticsOrder = true">线下物流单号</el-button>
      <el-button type="primary" size="mini" @click="isOpenSetSubmitSku = true" v-hasPermi="['system:erp_auto:click']">
        设置店铺不自动提交sku
      </el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-tabs v-model="tabsValue" type="border-card" @tab-click="tabsClick">
      <el-tab-pane v-for="(item,index) in tabsList" :key="index" :label="item.label" :name="item.name">
        <!--        <div slot="label" v-if="item.label=='截单订单'">-->
        <!--          截单订单-->
        <!--          <el-badge :value="cutOffNum"></el-badge>-->
        <!--        </div>-->
        <el-row style="margin-bottom: 10px">
          <!--          <el-button size="mini" type="primary" v-if="item.name == 701 || item.name == 901 || tabsValue == 502"-->
          <!--                     @click="changeOrderStatus(chooseOrderList,101)">转待发货审核-->
          <!--          </el-button>-->
          <el-button size="mini" type="primary" v-if="item.name == 101" :disabled="multiple"
                     @click="selfShipment()" v-hasPermi="['system:erp-operate:edit']">转自发货
          </el-button>
        </el-row>
        <el-table v-loading="loading" default-expand-all row-key="id" :key="isChooseOrder"
                  :data="groupOrderList" stripe border :row-class-name="tableRowClassName"
                  :tree-props="{children: 'sellerChildOrderList'}">
          <el-table-column width="50" align="center">
            <template slot="header" slot-scope="scope">
              <el-checkbox v-model="checkAll" @change="selectAllCheckbox()"></el-checkbox>
            </template>
            <template slot-scope="scope">
              <div v-if="!scope.row.childOrderId">
                <el-checkbox v-model="scope.row.checkValue" @change="changeCheckbox(scope.row)"></el-checkbox>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="买家信息" min-width="250" prop="orderId">
            <template slot-scope="scope">
              <div v-if="!scope.row.childOrderId">
                <div>
                  <span>买家姓名：</span>
                  <span>{{ scope.row.aeStoreOrderReceiptAddress.contactPerson }}</span>
                  <el-button class="ml10" size="mini" type="warning" @click="goChatPage(scope.row)">联系买家</el-button>
                </div>
                <div>
                  <span>电话：</span>
                  <span>{{
                      scope.row.aeStoreOrderReceiptAddress.phoneCountry + scope.row.aeStoreOrderReceiptAddress.mobileNo
                    }}</span>
                </div>
                <div style="display: flex">
                  <span>国家：</span>
                  <span>
                    <dict-tag :options="dict.type.county_code"
                              :value="scope.row.aeStoreOrderReceiptAddress.country"></dict-tag>
                  </span>
                </div>
                <div>
                  <span>收货地址：</span>
                  <span>
                    {{ scope.row.aeStoreOrderReceiptAddress.detailAddress }}
                    {{ scope.row.aeStoreOrderReceiptAddress.city }}
                    {{ scope.row.aeStoreOrderReceiptAddress.province }}
                    {{ scope.row.aeStoreOrderReceiptAddress.country }}
                    {{ scope.row.aeStoreOrderReceiptAddress.zip }}
                  </span>
                </div>
              </div>
              <div v-else>
                <div class="img-box">
                  <span>商品主图：</span>
                  <imagePreview :src="scope.row.snapshotSmallPhotoPath" width="50px" height="50px"/>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="商品信息" min-width="300">
            <template slot-scope="scope">
              <div v-if="scope.row.childOrderId">
                <div>
                  <span>ProductID：</span>
                  <span>{{ scope.row.productId }}</span>
                </div>
                <div>
                  <span>产品ID：</span>
                  <span>{{ scope.row.collectProductId }}</span>
                </div>
                <div>
                  <span>商品编码：</span>
                  <span>{{ scope.row.skuCode }}</span>
                </div>
                <div>
                  <el-tooltip effect="dark" :content="scope.row.productName" placement="top">
                    <el-button type="text">
                      <div class="hidden-box" @click="goPersonalProduct(scope.row)">
                        商品名称：{{ scope.row.productName }}
                      </div>
                    </el-button>
                  </el-tooltip>
                </div>
                <div>
                  <span>买家选择物流方式：</span>
                  <span>{{ scope.row.logisticsType }}</span>
                </div>
              </div>
              <div v-else>
                订单号：{{ scope.row.orderId }}
                <div>
                  <span>店铺：</span>
                  <span>{{ scope.row.sellerLoginId }}</span>
                </div>
                <div>
                  <span>卖家全名：</span>
                  <span>{{ scope.row.sellerSignerFullname }}</span>
                </div>
                <div style="color: #ff4949" v-if="scope.row.statusIntro">
                  <span>订单信息：</span>
                  <span>{{ scope.row.statusIntro }}</span>
                </div>
                <div v-if="scope.row.leftEndGoodTime" style="color: #ff4949">
                  <span>剩余时间：</span>
                  <span>
                    <count-down :endTime="endTime(scope.row.leftEndGoodTime)" endText="已结束"/>
                  </span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="订单金额" prop="bizType" min-width="150">
            <template slot-scope="scope">
              <div v-if="scope.row.childOrderId">
                <div>
                  <span>采购成本：</span>
                  <span v-if="scope.row.orderData.payCurrencyCode == 'USD'">
                    {{ scope.row.skuPrice == null ? '未知' : countPrice(scope.row.skuPrice) + 'RMB' }}
                  </span>
                  <span v-else>{{
                      scope.row.skuPrice == null ? '未知' : countPrice(scope.row.skuPrice) + 'RMB'
                    }} </span>
                  <div>
                    <span>商品数量：</span>
                    <span>{{ scope.row.productCount }}</span>
                  </div>
                  <div>
                    <span>商品规格：</span>
                    <span>{{ scope.row.skuPropertyIds }}</span>
                  </div>
                </div>
              </div>
              <div v-else>
                <div v-if="scope.row.payCurrencyCode == 'USD'">
                  <div>订单金额：{{
                      scope.row.payAmount == null ? '未知' : countPrice(scope.row.payAmount) + 'RMB'
                    }}
                  </div>
                  <div>
                    联盟佣金：{{
                      scope.row.afflicateFeeRate == null ? '未知' : countPrice(scope.row.afflicateFeeRate) + 'RMB'
                    }}
                  </div>
                  <div>
                    交易佣金：{{
                      scope.row.escrowFeeRate == null ? '未知' : countPrice(scope.row.escrowFeeRate) + 'RMB'
                    }}
                  </div>
                  <div>预估利润：
                    {{
                      scope.row.estimatedProfit == null ? '未知' : countPrice(scope.row.estimatedProfit) + 'RMB'
                    }}
                  </div>
                </div>
                <div v-else>
                  <div>订单金额：{{
                      scope.row.payAmount == null ? '未知' : countPrice(scope.row.payAmount) + 'RMB'
                    }}
                  </div>
                  <div>
                    联盟佣金：{{
                      scope.row.afflicateFeeRate == null ? '未知' : countPrice(scope.row.afflicateFeeRate) + 'RMB'
                    }}
                  </div>
                  <div>
                    交易佣金：{{
                      scope.row.escrowFeeRate == null ? '未知' : countPrice(scope.row.escrowFeeRate) + 'RMB'
                    }}
                  </div>
                  <div>预估利润：{{
                      scope.row.estimatedProfit == null ? '未知' : countPrice(scope.row.estimatedProfit) + 'RMB'
                    }}
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="时间" prop="orderStatus" min-width="200">
            <template slot-scope="scope">
              <div v-if="!scope.row.childOrderId">
                <div>创建时间：{{ scope.row.gmtCreate }}</div>
                <div>更新时间： {{ scope.row.updateTime }}</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.childOrderId">
                <el-button v-if="tabsValue == 111" size="mini" type="text"
                           @click="openPurchaseInfo(scope.row)">上传采购信息
                </el-button>
                <el-button v-if="tabsValue==111" size="mini" type="text"
                           @click="openSendInfo(scope.row)">上传发货信息
                </el-button>
              </div>
              <div v-else>
                <el-button size="mini" type="text" @click="openOrderDetail(scope.row)">详情</el-button>
                <el-button size="mini" type="text" @click="getOrderLog(scope.row)">查看订单记录</el-button>
                <el-button size="mini" type="text" v-if="tabsValue == 101"
                           @click="changeOrderStatus(scope.row,103)">提交审核
                </el-button>
                <el-button size="mini" type="text" v-if="tabsValue == 101"
                           @click="selfShipment(scope.row)" v-hasPermi="['system:erp-operate:edit']">转自发货
                </el-button>
                <el-button size="mini" type="text" v-if="tabsValue == 701"
                           @click="getAbnormalCause(scope.row)">查看异常原因
                </el-button>
                <el-button size="mini" type="text"
                           v-if="tabsValue == 103  || tabsValue == 701 || tabsValue == 114"
                           @click="applyCutoff(scope.row)">申请截单
                </el-button>
                <el-button size="mini" type="text"
                           v-show="tabsValue == 701 || tabsValue == 901 || scope.row.erpInnerOrderStatus != 501"
                           @click="changeOrderStatus(scope.row,101)">转待发货审核
                </el-button>
                <el-button size="mini" type="text"
                           v-if="tabsValue == 701 || tabsValue == 100 || tabsValue == 502 || tabsValue == 101"
                           @click="changeOrderStatus(scope.row,901)">作废
                </el-button>
                <!--                <el-button size="mini" type="text"-->
                <!--                           v-if="scope.row.erpInnerOrderStatus == 103 || scope.row.erpInnerOrderStatus == 1031"-->
                <!--                           @click="warehouseShipment(scope.row)">仓储发货-->
                <!--                </el-button>-->
              </div>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!--  申请截单  -->
    <el-dialog
      title="填写截单信息"
      :visible.sync="isApplyCutoffModal"
      width="500px">
      <el-form :model="applyCutoffInfo" :rules="applyCutoffRules" ref="applyCutoffInfo" size="small"
               label-width="100px">
        <el-form-item label="截单原因：" prop="cancelType">
          <el-select v-model="applyCutoffInfo.cancelType" placeholder="请选择截单原因" @change="chooseCancelType">
            <el-option v-for="(item,index) in dict.type.erp_cut_order_type" :key="index" :label="item.label"
                       :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注：" prop="cancelRemark" v-if="applyCutoffInfo.isShowCutoffRemark">
          <el-input type="textarea" v-model="applyCutoffInfo.cancelRemark" placeholder="请输入截单原因（其他原因）"
                    clearable/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="isApplyCutoffModal = false">取 消</el-button>
        <el-button type="primary" @click="confirmCutoffOrder">确 定</el-button>
      </div>
    </el-dialog>
    <!--  AE速卖通拉取订单  -->
    <el-dialog
      title="AE从速卖通获取订单"
      :visible.sync="isShowAeOrder"
      width="500px">
      <el-form :model="aeOrderInfo" :rules="aeOrderRules" ref="aeOrderInfo" size="small"
               label-width="120px">
        <el-form-item label="选择店铺：" prop="sellerId">
          <el-select v-model="aeOrderInfo.sellerId" placeholder="请选择店铺">
            <el-option v-for="(item,index) in storeList" :key="index" :label="item.storeName"
                       :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单创建时间：" prop="createDateStart">
          <el-date-picker clearable v-model="aeOrderInfo.createDateStart" type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择订单创建时间"></el-date-picker>
        </el-form-item>
        <el-form-item label="订单结束时间：" prop="createDateEnd">
          <el-date-picker clearable v-model="aeOrderInfo.createDateEnd" type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择订单结束时间"></el-date-picker>
        </el-form-item>
        <!--        <el-form-item label="备注：" prop="goodsWidth" v-if="applyCutoffInfo.isShowCutoffRemark">-->
        <!--          <el-input type="textarea" v-model="applyCutoffInfo.cancelRemark" placeholder="请输入截单原因（其他原因）"-->
        <!--                    clearable/>-->
        <!--        </el-form-item>-->
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isShowAeOrder = false">取 消</el-button>
        <el-button type="primary" @click="getAeOrderList">确 定</el-button>
      </span>
    </el-dialog>
    <!--  上传采购信息  -->
    <UploadPurchaseInfo v-if="isOpenPurchaseInfo" :childOrderId="childOrderId" @closePurchaseInfo="closePurchaseInfo"/>
    <!--  上传发货信息  -->
    <UploadSendInfo v-if="isOpenSendInfo" :orderId="orderId" @closeSendInfo="closeSendInfo"/>
    <!--    订单详情-->
    <order-detail v-if="isOpenOrderDetail" :id="orderId" @orderDetailSwitch="orderDetailSwitch"/>
    <!-- 订单日志 -->
    <order-log v-if="isShowOrderLog" :orderId="orderId" @closeOrderLogModal="closeOrderLogModal"/>
    <!--  从速卖通获取单个订单  -->
    <getOneOrderByAe v-if="isShowAeOneOrder" :storeList="storeList" @close="closeAeOneOrderModal"/>
    <!--  线下物流单号  -->
    <offlineLogisticsOrder v-if="isOpenOfflineLogisticsOrder" :storeList="storeList"
                           @close="closeOfflineLogisticsOrder"/>
    <!--  设置店铺不自动提交sku  -->
    <autoSubmitSku v-if="isOpenSetSubmitSku" @close="isOpenSetSubmitSku = false"/>
  </div>
</template>

<script>
import offlineLogisticsOrder from "@/views/order/components/offlineLogisticsOrder.vue";
import orderDetail from '@/views/components/order/order-detail';
import {
  listSellerOrder,
  alterInnerStatus,
  warehousGoodsOutFPX,
  cutOrderApplication,
  submitForReview,
  getAEOrderList,
  cancelOrder,
  addCollectLink,
  specialCause,
  sellerShipmentForTop, chooseSelfShipments
} from '@/api/order/orderApi';
import detail from "../picture/detail.vue";
import countDown from '@/views/components/countDown/index';
import upload from "element-ui/packages/upload";
import UploadPurchaseInfo from "@/views/order/components/UploadPurchaseInfo.vue";
import UploadSendInfo from "@/views/order/components/UploadSendInfo.vue";
import orderLog from "@/views/order/components/orderLog.vue";
import getOneOrderByAe from "@/views/order/components/getOneOrderByAe.vue";
import {redReminderForCutOffOrder} from "@/api/order/purchaser";
import {queryCookieInd} from "@/api/shop";
import {getSessionld} from "@/api/autoOperation/python";
import autoSubmitSku from "@/views/order/components/autoSubmitSku.vue";
import {queryUserShopList} from "@/api/shop";

export default {
  name: 'Order-list',
  components: {
    orderDetail,
    countDown,
    UploadPurchaseInfo,
    UploadSendInfo,
    orderLog, getOneOrderByAe, offlineLogisticsOrder, autoSubmitSku
  },
  dicts: ['erp_inner_order_status', 'ae_order_type', 'ae_order_status', "erp_cut_order_type", 'county_code', 'erp_order_process_flag'],
  data() {
    return {
      isOpenOfflineLogisticsOrder: false,//是否打开线下物流单号弹窗
      isOpenSetSubmitSku: false,//是否打开设置不自动提交sku组件
      checkAll: false,
      aeOrderInfo: {},// ae订单表单信息
      erpOrderInfo: {},// erp订单表单信息
      isShowAeOrder: false,//是否显示AE获取订单弹窗
      isShowAeOneOrder: false,//从速卖通获取单个订单
      applyCutoffModal: false,//申请截单弹窗
      isApplyCutoffModal: false,
      applyCutoffInfo: {},
      orderId: '',
      loading: false, // 遮罩层
      chooseOrderList: [], // 选中数组
      single: true, // 非单个禁用
      multiple: true, // 非多个禁用
      showSearch: true, // 显示搜索条件
      total: 0, // 总条数
      title: '订单详情', // 弹出层标题
      isOpenOrderDetail: false, // 是否打开订单详情弹窗
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: undefined,
        bizType: undefined,
        gmtCreate: undefined,
        gmtPayTime: undefined,
        orderStatus: undefined,
        erpInnerOrderStatus: "101",
        userId: "",
        orderProcessFlag: "",
        type: '0',
      }, // 查询参数
      tabsValue: '101',
      applyCutoffRules: {
        cancelType: [{
          required: true,
          message: '请选择截单原因',
          trigger: 'change'
        }],
        cancelRemark: [{
          required: true,
          message: '请输入截单原因',
          trigger: 'blur'
        }]
      },
      tabsList: [{
        name: '101',
        label: '待发货审核'
      }, {
        name: '103',
        label: '待发货'
      }, {
        name: '107',
        label: '已发货'
      }, {
        name: '701',
        label: '问题件'
      }, {
        name: '901',
        label: '已作废'
      }, {
        name: '502',
        label: '截单订单'
      }, {
        name: '111',
        label: '自发货订单'
      }, {
        name: '110',
        label: '测评订单'
      }, {
        name: '333',
        label: '外部订单'
      }, {
        name: '114',
        label: '已完成'
      }],
      orderDetailForm: {}, // 订单详情
      form: '',
      aeOrderRules: {
        sellerId: [{
          required: true,
          message: '店铺不能为空',
          trigger: 'change'
        }],
        createDateStart: [{
          required: false,
          message: '开始时间不能为空',
          trigger: 'change'
        }],
        createDateEnd: [{
          required: false,
          message: '结束时间不能为空',
          trigger: 'change'
        }],
      },
      // orderStatusData: { 101: '提交审核', 100: '作废', 502: '作废', 701: '作废', 102: '申请截单', 107: '申请截单', 901: '转发货审核'
      // }, //订单修改状态
      orderStatusData: {
        101: '转发货审核',
        901: '作废',
        103: '提交审核',
        501: '申请截单',
        601: '申请仓储',
      }, //订单修改状态
      storeList: [],
      spanArr: [],//用于存放每一行记录的合并数
      sellerOrderList: [], // 订单表格数据
      checkValue: false,
      isChooseOrder: false,

      orderLogList: [],//订单日志列表
      isOldOrder: false,
      collectInfo: {},//填写采集信息
      collectRules: {
        collectLink: [{
          required: true,
          message: '采集链接不能为空',
          trigger: 'blur'
        }],
      },
      isShowAbnormalCause: false,//是否显示订单异常原因弹窗
      isOpenPurchaseInfo: false,//是否打开采购信息弹窗
      isOpenSendInfo: false,//是否打开发货信息弹窗
      childOrderId: "",//子订单id
      isShowOrderLog: false,//是否显示订单日志
      cutOffNum: 0,//截单订单数量
    }
  },
  computed: {
    upload() {
      return upload
    },
    groupOrderList: {
      get() {
        return this.sellerOrderList
      },
      set(val) {
        console.log('val', val)
        this.sellerOrderList = val
        // this.$set(this.form.expand, 'freightMap', JSON.stringify(val || []))
        // this.$emit('input', val.map(item => item.name).join(';'))
      }
    },
    endTime() {
      return time => {
        return new Date(time).getTime() / 1000 + ' '
      }
    },
    detail() {
      return detail
    }
  },
  created() {
    // this.getCutOffNum()// 获取截单订单数量
    this.userInfo = this.$store.state.user.urserInfo
    this.getList()
    this.getStoreList()
  },
  methods: {
    // 前往聊天页面
    goChatPage(row) {
      this.storeList.forEach((item, index) => {
        if (item.storeUserName == row.sellerLoginId) {
          queryCookieInd({storeId: item.id}).then(res => {
            if (res.data) {
              let cookie = res.data.cookie
              let data = {
                "cookie_str": cookie,
                "orderno": row.orderId.toString()
              }
              getSessionld(data).then(res => {
                let sessionId = res.data.sessionId
                this.$router.push({
                  path: "selfOperation/autoChat",
                  query: {
                    sessionId: sessionId,
                    // sessionId: "2#103#2674993116#12#2947280029#11",
                    cookie_str: cookie,
                    country: row.aeStoreOrderReceiptAddress.country,
                    orderno: row.orderId
                  }
                })
              })
            } else {
              this.$message.error('该店铺未提交cokkie或cookie已失效，请前往店铺列表提交cookie！')
            }
          })
        }
      })


    },
    // 关闭线下物流单号弹窗
    closeOfflineLogisticsOrder() {
      this.isOpenOfflineLogisticsOrder = false
    },
    // 跳转个人产品库
    goPersonalProduct(row) {
      const params = {v1: row.collectProductId, v2: '0'};
      this.$tab.openPage("产品详情", './publicProductDetail', params)
    },
    // 关闭从速卖通获取单个订单弹窗
    closeAeOneOrderModal(e) {
      this.isShowAeOneOrder = false
      if (e == '1') {
        this.getList()
      }
    },
    // 打开上传采购信息弹窗
    openPurchaseInfo(row) {
      this.childOrderId = row.childOrderId
      this.isOpenPurchaseInfo = true
    },
    // 打开上传发货信息弹窗
    openSendInfo(row) {
      this.orderId = row.orderId
      this.isOpenSendInfo = true
    },
    // 关闭上传采购信息弹窗
    closePurchaseInfo(e, isRefresh) {
      if (isRefresh == '1') {
        this.getList()
      }
      this.isOpenPurchaseInfo = e
    },
    // 关闭上传发货信息弹窗
    closeSendInfo(e, isRefresh) {
      this.isOpenSendInfo = e
      if (isRefresh == '1') {
        this.getList()
      }
    },
    // 打开从速卖通获取单个订单弹窗
    openAeOneOrderModal() {
      this.isShowAeOneOrder = true
    },
    // 从AE获取速卖通订单
    getAeOrderList() {
      getAEOrderList(this.aeOrderInfo).then(response => {
        this.sellerStoreEmpowerList = response.rows;
        this.$message.success(response.msg)
        this.loading = false;
        this.isShowAeOrder = false
        this.getList()
      });
    },
    // 查看异常原因
    getAbnormalCause(row) {
      let data = {
        orderId: row.orderId
      }
      specialCause(data).then(res => {
        console.log('异常原因res', res)
        // this.isShowAbnormalCause = true
        this.$alert(res, '订单异常原因', {
          confirmButtonText: '确定',
          callback: action => {
            // this.$message({
            //   type: 'info',
            //   message: `action: ${action}`
            // });
          }
        });
      })
    },
    // 查看订单日志
    getOrderLog(row) {
      this.orderId = row.orderId
      this.isShowOrderLog = true
    },
    // 关闭订单日志
    closeOrderLogModal(e) {
      this.isShowOrderLog = e
    },
    // 全选
    selectAllCheckbox(selection) {
      const ls = [...this.groupOrderList]
      // console.log('selection', selection)
      // this.checkAll = !this.checkAll
      // console.log('ls', ls)
      if (this.checkAll == true) {
        this.chooseOrderList = ls.map(item => item.orderId)
      } else {
        this.chooseOrderList = []
      }
      this.multiple = !this.chooseOrderList.length

      ls.forEach((item) => {
        // console.log('this.checkAll', this.checkAll == true)
        item.checkValue = this.checkAll
      })

      // console.log(' this.chooseOrderList', this.chooseOrderList)
      this.groupOrderList = ls
    },
    // 选择单选框
    changeCheckbox(selection) {
      const ls = [...this.groupOrderList]
      ls.forEach((item) => {
        if (selection.orderId == item.orderId) {
          item.checkValue = selection.checkValue
          if (selection.checkValue) {
            this.chooseOrderList.push(selection.orderId)
          } else {
            this.chooseOrderList = this.chooseOrderList.filter(item => item !== selection.orderId);
          }
        }
      })
      // console.log('this.chooseOrderList', this.chooseOrderList)
      this.groupOrderList = ls
      this.multiple = !this.chooseOrderList.length
    },
    // 选择截单原因
    chooseCancelType(e) {
      if (e == "OT") {
        this.applyCutoffInfo.isShowCutoffRemark = true;
      } else {
        this.applyCutoffInfo.isShowCutoffRemark = false;
      }
    },
    // 确定截单
    confirmCutoffOrder() {
      this.$refs["applyCutoffInfo"].validate(valid => {
        if (valid) {
          cutOrderApplication({
            orderId: this.orderId,
            userId: this.userInfo.userId,
            cancelType: this.applyCutoffInfo.cancelType,
            cancelRemark: this.applyCutoffInfo.cancelRemark
          }).then(res => {
            this.$message({
              type: 'success',
              message: res.msg
            })
            this.isApplyCutoffModal = false
            this.applyCutoffInfo.isShowCutoffRemark = false
            this.getList() // 修改完状态后再次获取订单列表
          })
        }
      });
    },
    // 切换选项卡
    tabsClick(tab, event) {
      this.queryParams.erpInnerOrderStatus = tab.name
      this.getList()
    },
    // 申请截单
    applyCutoff(row) {
      this.orderId = row.orderId
      this.isApplyCutoffModal = true
    },
    // 设置表格颜色
    tableRowClassName({row, rowIndex}) {
      if (!row.childOrderId) {
        return 'warning-row';
      }
    },
    // 自发货
    selfShipment(row) {
      // console.log('this.chooseOrderList', this.chooseOrderList)
      const id = row ? row.orderId : this.chooseOrderList.toString()
      console.log('id', id)
      this.$confirm('是否确定将订单改为自发货状态？', '提示').then(() => {
        chooseSelfShipments({orderIds: id}).then(res => {
          this.$message.success(res.msg)
          this.getList()
        })
      })
    },
    // 修改订单状态
    changeOrderStatus(row, status) {
      let isMultiple = Array.isArray(row)
      if (isMultiple && row.length < 1) {
        this.$message.error("请至少选择一项订单")
        return
      }
      let orderIds = [];
      if (this.chooseOrderList && this.chooseOrderList.length > 0) {
        orderIds = this.chooseOrderList
      } else {
        orderIds.push(row.orderId)
      }
      this.orderId = orderIds
      let statusText = this.orderStatusData[status]
      this.$confirm('是否确定执行' + statusText + '操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        if (status == 103) {
          // 提交待发货审核
          this.submitReview()
        } else if (status == 901) {
          this.cancelOrder(orderIds) //作废订单
        } else {
          // x修改订单状态
          alterInnerStatus({
            orderIds: orderIds,
            erpInnerOrderStatus: status
          }).then(res => {
            this.$message({type: 'success', message: res.msg})
            this.getList() // 修改完状态后再次获取订单列表
          })
        }
      })

    },
    // 提交待审核订单
    submitReview() {
      submitForReview({
        orderIds: this.orderId,
        erpInnerOrderStatus: 103,
        userId: this.userInfo.userId,
        type: "1",// 0 自动化，1 手动提交
      }).then(res => {
        this.$message({
          type: 'success',
          message: res.msg
        })
        this.getList() // 修改完状态后再次获取订单列表
      })
    },
    // 添加采集链接
    addCollectLink() {
      this.collectInfo.orderId = this.orderId.toString()
      addCollectLink(this.collectInfo).then(res => {
        this.$message({
          type: 'success',
          message: res.msg
        })
        this.isOldOrder = false
        this.submitReview()
      })
    },
    // 取消订单
    cancelOrder(orderIds) {
      cancelOrder({
        orderIds: orderIds,
      }).then(res => {
        this.$message({
          type: 'success',
          message: res.msg
        })
        this.getList() // 修改完状态后再次获取订单列表
      })
    },
    // 订单详情弹窗开关
    orderDetailSwitch(e) {
      this.isOpenOrderDetail = e
    },
    // 获取截单订单数量
    getCutOffNum() {
      // this.queryParams.statusList = undefined
      redReminderForCutOffOrder().then(response => {
        this.cutOffNum = response.data.cutOffNum
      })
    },
    /** 查询卖家订单列表 */
    getList() {
      this.loading = true
      this.queryParams.statusList = undefined
      // let orderProcessFlag = this.dict.type.erp_order_process_flag
      let orderProcessFlag = {
        "101": ['begin'],
        "103": ['cainiao', 'offline', 'begin', 'companyEva'],
        "107": ['cainiao', 'offline'],
        "701": ["problem"],
        "901": ["invalid"],
        "502": ["cutoff"],
        "111": ["myself"],
        "110": ["evaluation"],
        "333": ["out"]
      }
      // console.log('%%%', orderProcessFlag)
      this.queryParams.orderProcessFlag = orderProcessFlag[this.tabsValue]
      if (this.tabsValue == '101') {
        this.queryParams.statusList = ['101']
      }
      if (this.tabsValue == '103') {
        this.queryParams.statusList = ['103', '104', '105', '106', '1061', '1031', '108', '109', '116', '115']
      }
      if (this.tabsValue == '107') { // 待组包 109  待声明发货 108 已发货 107
        this.queryParams.statusList = ['107', '1071']
      }
      if (this.tabsValue == '114') { // 待组包 109  待声明发货 108 已发货 107
        this.queryParams.statusList = ['114']
      }
      // if (this.tabsValue == '502') {
      //   this.queryParams.statusList = ['501', '502']
      // }
      // if (this.tabsValue == '111') { // 111待填写采购信息  112待填写发货信息
      //   this.queryParams.statusList = ['111', '112']
      // }
      // this.queryParams.userId = this.userInfo.userId
      listSellerOrder(this.queryParams).then(response => {
        let list = response.rows
        let childList = []
        this.sellerOrderList = list
        for (let i = 0; i < list.length; i++) {
          // childList.push(list[i].sellerChildOrderList)
          this.sellerOrderList[i]['checkValue'] = false
          for (let j = 0; j < list[i].sellerChildOrderList.length; j++) {
            if (list[i].orderId == list[i].sellerChildOrderList[j].orderId) {
              this.sellerOrderList[i].sellerChildOrderList[j]['erpInnerOrderStatus'] = this.sellerOrderList[i].erpInnerOrderStatus
              this.sellerOrderList[i].sellerChildOrderList[j]['orderData'] = this.sellerOrderList[i]
              this.sellerOrderList[i].sellerChildOrderList[j].id = String(this.sellerOrderList[i].sellerChildOrderList[j].id)
            }
          }
        }
        this.chooseOrderList = [] // 清空所选择的订单
        this.total = response.total
        this.loading = false
      })
    },
    //  获取店铺列表
    getStoreList() {
      this.loading = true
      queryUserShopList().then(response => {
        let list = response.data
        this.storeList = list
      })
    },
    // 仓储发货
    warehouseShipment(row) {
      this.$confirm('是否要执行仓储发货操作', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        let data = {
          orderId: row.orderId
        }
        warehousGoodsOutFPX(data).then(response => {

        })
      }).catch(() => {

      })
    },
    // 取消按钮
    cancel() {
      this.isOpenOrderDetail = false
      this.reset()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      console.log(this.queryParams)
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    //查看订单详情
    openOrderDetail(row) {
      this.orderId = row.orderId
      this.isOpenOrderDetail = true
    },
    // 声明发货
    sellerShipmentForTopFn(row) {
      this.$confirm('是否要执行声明发货操作', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        const params = {
          orderId: row.orderId,
          storeId: row.sellerLoginId
        }
        sellerShipmentForTop(params).then(res => {

        })
      }).catch(() => {

      })
    }
  }
}
</script>
<style>
.el-table .warning-row {
  background: #fff1ca;
}

.demo-table-expand label {
  width: 100px;
  color: #99a9bf;
  padding: 0;
}

.el-form-item el-form-item--small {
  margin-bottom: 0;
}

.el-form--label-left .el-form-item__label {
  text-align: right;
}

.demo-table-expand .el-form-item {
  width: 16%;
  margin-bottom: 0;
  margin-right: 0;
}

.img-box {
  display: flex;
  align-items: flex-start;
}

.hidden-box {
  /*min-width: 350px;*/
  width: 500px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
